// Author: Ben
// Project: CR_RandomBackgroundChanger
// Path: D:\code\Abi\CR_RandomBackgroundChanger
// Creation date: 26.04.2008 15:09
// Last modified: 6/2/2009 9:42 AM

#region Using directives
using DevExpress.CodeRush.Core;
using EnvDTE;
using System;
using System.Collections;
using System.Security.Principal;
using System.Windows.Forms;
using Process=System.Diagnostics.Process;
using Project=DevExpress.CodeRush.Core.Project;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
#endregion

namespace CR_RandomBackgroundChanger
{
  /// <summary>
  /// The OptionsPage for the Commenter plugin, show it to all users
  /// (not only in expert mode).
  /// </summary>
  /// <returns>Options page</returns>
	[UserLevel(UserLevel.NewUser)]
	public class BackgroundChangerOptionsPage : OptionsPage
	{
		#region Variables
		/// <summary>
		/// Check box enabled
		/// </summary>
		private System.Windows.Forms.CheckBox checkBoxEnabled;
		/// <summary>
		/// Label about 1
		/// </summary>
		private System.Windows.Forms.Label labelAbout1;
		/// <summary>
		/// Label about 3
		/// </summary>
		private System.Windows.Forms.Label labelAbout3;
		/// <summary>
		/// Link label about 2
		/// </summary>
		private System.Windows.Forms.LinkLabel linkLabelAbout2;
		/// <summary>
		/// Picture box 1
		/// </summary>
		private System.Windows.Forms.PictureBox pictureBoxIcon;
		/// <summary>
		/// Label version info
		/// </summary>
		private Label labelVersionInfo;
		/// <summary>
		/// Link label update
		/// </summary>
		private LinkLabel linkLabelUpdate;
		/// <summary>
		/// Text box 2
		/// </summary>
		private TextBox textBoxDirectory;
		/// <summary>
		/// Label directory
		/// </summary>
		private Label labelDirectory;
		/// <summary>
		/// Label preview
		/// </summary>
		private Label labelPreview;
		/// <summary>
		/// Button select directory
		/// </summary>
		private Button buttonSelectDirectory;
		/// <summary>
		/// Label transparency
		/// </summary>
		private Label labelTransparency;
		/// <summary>
		/// Track bar transparency
		/// </summary>
		private TrackBar trackBarTransparency;
		/// <summary>
		/// Button next
		/// </summary>
		private Button buttonNext;
		/// <summary>
		/// Check box different backgrounds
		/// </summary>
		private CheckBox checkBoxDifferentBackgrounds;
		/// <summary>
		/// Check box minutes
		/// </summary>
		private CheckBox checkBoxMinutes;
		/// <summary>
		/// Text box minutes
		/// </summary>
		private TextBox textBoxMinutes;
		/// <summary>
		/// Label minutes
		/// </summary>
		private Label labelMinutes;
		private Panel panelPreview;
		/// <summary>
		/// Components
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion

		#region BackgroundChangerOptionsPage
		/// <summary>
		/// Constructor
		/// </summary>
		public BackgroundChangerOptionsPage()
			: base()
		{
			// Required for Windows.Forms Class Composition Designer support
			InitializeComponent();
		} // BackgroundChangerOptionsPage()
		#endregion

		#region CodeRush generated code
		/// <summary>
		/// Initialize
		/// </summary>
		protected override void Initialize()
		{
			base.Initialize();
		} // Initialize()

		/// <summary>
		/// Get category
		/// </summary>
		public static string GetCategory()
		{
			return @"Editor";
		} // GetCategory()

		/// <summary>
		/// Get page name
		/// </summary>
		public static string GetPageName()
		{
			return @"RandomBackgroundChanger";
		} // GetPageName()

		/// <summary>
		/// Get level
		/// </summary>
		public static UserLevel GetLevel()
		{
			return DevExpress.CodeRush.Core.CodeRush.Options.GetLevel(
				typeof(OptionsPage));
		} // GetLevel()

		/// <summary>
		/// Storage
		/// </summary>
		public static DecoupledStorage Storage
		{
			get
			{
				return DevExpress.CodeRush.Core.CodeRush.Options.GetStorage(
					GetCategory(), GetPageName());
			} // get
		} // Storage

		/// <summary>
		/// Category
		/// </summary>
		public override string Category
		{
			get
			{
				return BackgroundChangerOptionsPage.GetCategory();
			} // get
		} // Category

		/// <summary>
		/// Page name
		/// </summary>
		public override string PageName
		{
			get
			{
				return BackgroundChangerOptionsPage.GetPageName();
			} // get
		} // PageName
		#endregion

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BackgroundChangerOptionsPage));
			this.checkBoxEnabled = new System.Windows.Forms.CheckBox();
			this.textBoxDirectory = new System.Windows.Forms.TextBox();
			this.labelAbout1 = new System.Windows.Forms.Label();
			this.linkLabelAbout2 = new System.Windows.Forms.LinkLabel();
			this.labelAbout3 = new System.Windows.Forms.Label();
			this.pictureBoxIcon = new System.Windows.Forms.PictureBox();
			this.labelVersionInfo = new System.Windows.Forms.Label();
			this.linkLabelUpdate = new System.Windows.Forms.LinkLabel();
			this.labelDirectory = new System.Windows.Forms.Label();
			this.labelPreview = new System.Windows.Forms.Label();
			this.buttonSelectDirectory = new System.Windows.Forms.Button();
			this.labelTransparency = new System.Windows.Forms.Label();
			this.trackBarTransparency = new System.Windows.Forms.TrackBar();
			this.buttonNext = new System.Windows.Forms.Button();
			this.checkBoxDifferentBackgrounds = new System.Windows.Forms.CheckBox();
			this.checkBoxMinutes = new System.Windows.Forms.CheckBox();
			this.textBoxMinutes = new System.Windows.Forms.TextBox();
			this.labelMinutes = new System.Windows.Forms.Label();
			this.panelPreview = new System.Windows.Forms.Panel();
			((System.ComponentModel.ISupportInitialize)(this.pictureBoxIcon)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBarTransparency)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			this.SuspendLayout();
			// 
			// checkBoxEnabled
			// 
			this.checkBoxEnabled.Location = new System.Drawing.Point(11, 9);
			this.checkBoxEnabled.Name = "checkBoxEnabled";
			this.checkBoxEnabled.Size = new System.Drawing.Size(490, 17);
			this.checkBoxEnabled.TabIndex = 0;
			this.checkBoxEnabled.Text = "Enable Random Background Changer: Will set background image for all text editor d" +
					"ocuments";
			this.checkBoxEnabled.CheckedChanged += new System.EventHandler(this.checkBoxEnabled_CheckedChanged);
			// 
			// textBoxDirectory
			// 
			this.textBoxDirectory.Location = new System.Drawing.Point(11, 49);
			this.textBoxDirectory.Name = "textBoxDirectory";
			this.textBoxDirectory.Size = new System.Drawing.Size(504, 20);
			this.textBoxDirectory.TabIndex = 2;
			// 
			// labelAbout1
			// 
			this.labelAbout1.Location = new System.Drawing.Point(199, 462);
			this.labelAbout1.Name = "labelAbout1";
			this.labelAbout1.Size = new System.Drawing.Size(183, 16);
			this.labelAbout1.TabIndex = 12;
			this.labelAbout1.Text = "CR_RandomBackgroundChanger by";
			// 
			// linkLabelAbout2
			// 
			this.linkLabelAbout2.Location = new System.Drawing.Point(377, 462);
			this.linkLabelAbout2.Name = "linkLabelAbout2";
			this.linkLabelAbout2.Size = new System.Drawing.Size(147, 23);
			this.linkLabelAbout2.TabIndex = 11;
			this.linkLabelAbout2.TabStop = true;
			this.linkLabelAbout2.Text = "http://BenjaminNitschke.com";
			this.linkLabelAbout2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
			// 
			// labelAbout3
			// 
			this.labelAbout3.Location = new System.Drawing.Point(521, 462);
			this.labelAbout3.Name = "labelAbout3";
			this.labelAbout3.Size = new System.Drawing.Size(46, 16);
			this.labelAbout3.TabIndex = 13;
			this.labelAbout3.Text = "(c) 2009";
			// 
			// pictureBoxIcon
			// 
			this.pictureBoxIcon.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.pictureBoxIcon.Image = ((System.Drawing.Image)(resources.GetObject("pictureBoxIcon.Image")));
			this.pictureBoxIcon.Location = new System.Drawing.Point(524, 5);
			this.pictureBoxIcon.Name = "pictureBoxIcon";
			this.pictureBoxIcon.Size = new System.Drawing.Size(39, 39);
			this.pictureBoxIcon.TabIndex = 15;
			this.pictureBoxIcon.TabStop = false;
			// 
			// labelVersionInfo
			// 
			this.labelVersionInfo.AutoSize = true;
			this.labelVersionInfo.Location = new System.Drawing.Point(10, 462);
			this.labelVersionInfo.Name = "labelVersionInfo";
			this.labelVersionInfo.Size = new System.Drawing.Size(91, 13);
			this.labelVersionInfo.TabIndex = 23;
			this.labelVersionInfo.Text = "v1.0 (2009-05-31)";
			// 
			// linkLabelUpdate
			// 
			this.linkLabelUpdate.Location = new System.Drawing.Point(100, 462);
			this.linkLabelUpdate.Name = "linkLabelUpdate";
			this.linkLabelUpdate.Size = new System.Drawing.Size(89, 23);
			this.linkLabelUpdate.TabIndex = 10;
			this.linkLabelUpdate.TabStop = true;
			this.linkLabelUpdate.Text = "Check for update";
			this.linkLabelUpdate.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelUpdate_LinkClicked);
			// 
			// labelDirectory
			// 
			this.labelDirectory.AutoSize = true;
			this.labelDirectory.Location = new System.Drawing.Point(8, 33);
			this.labelDirectory.Name = "labelDirectory";
			this.labelDirectory.Size = new System.Drawing.Size(432, 13);
			this.labelDirectory.TabIndex = 30;
			this.labelDirectory.Text = "Directory for background images (sub directories will be included, only .jpg file" +
					"s are added):";
			// 
			// labelPreview
			// 
			this.labelPreview.AutoSize = true;
			this.labelPreview.Location = new System.Drawing.Point(8, 158);
			this.labelPreview.Name = "labelPreview";
			this.labelPreview.Size = new System.Drawing.Size(48, 13);
			this.labelPreview.TabIndex = 32;
			this.labelPreview.Text = "Preview:";
			// 
			// buttonSelectDirectory
			// 
			this.buttonSelectDirectory.Location = new System.Drawing.Point(521, 47);
			this.buttonSelectDirectory.Name = "buttonSelectDirectory";
			this.buttonSelectDirectory.Size = new System.Drawing.Size(43, 23);
			this.buttonSelectDirectory.TabIndex = 33;
			this.buttonSelectDirectory.Text = "...";
			this.buttonSelectDirectory.UseVisualStyleBackColor = true;
			this.buttonSelectDirectory.Click += new System.EventHandler(this.buttonSelectDirectory_Click);
			// 
			// labelTransparency
			// 
			this.labelTransparency.AutoSize = true;
			this.labelTransparency.Location = new System.Drawing.Point(8, 77);
			this.labelTransparency.Name = "labelTransparency";
			this.labelTransparency.Size = new System.Drawing.Size(226, 13);
			this.labelTransparency.TabIndex = 34;
			this.labelTransparency.Text = "Transparency to make text easier to read: 25%";
			// 
			// trackBarTransparency
			// 
			this.trackBarTransparency.Location = new System.Drawing.Point(4, 92);
			this.trackBarTransparency.Maximum = 100;
			this.trackBarTransparency.Name = "trackBarTransparency";
			this.trackBarTransparency.Size = new System.Drawing.Size(566, 45);
			this.trackBarTransparency.TabIndex = 15;
			this.trackBarTransparency.TickFrequency = 5;
			this.trackBarTransparency.Value = 25;
			this.trackBarTransparency.Scroll += new System.EventHandler(this.trackBarTransparency_Scroll);
			// 
			// buttonNext
			// 
			this.buttonNext.Location = new System.Drawing.Point(462, 150);
			this.buttonNext.Name = "buttonNext";
			this.buttonNext.Size = new System.Drawing.Size(102, 21);
			this.buttonNext.TabIndex = 36;
			this.buttonNext.Text = "Next Image";
			this.buttonNext.UseVisualStyleBackColor = true;
			this.buttonNext.Click += new System.EventHandler(this.buttonNext_Click);
			// 
			// checkBoxDifferentBackgrounds
			// 
			this.checkBoxDifferentBackgrounds.Checked = true;
			this.checkBoxDifferentBackgrounds.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkBoxDifferentBackgrounds.Location = new System.Drawing.Point(297, 129);
			this.checkBoxDifferentBackgrounds.Name = "checkBoxDifferentBackgrounds";
			this.checkBoxDifferentBackgrounds.Size = new System.Drawing.Size(269, 17);
			this.checkBoxDifferentBackgrounds.TabIndex = 38;
			this.checkBoxDifferentBackgrounds.Text = "Use different background image for each document";
			// 
			// checkBoxMinutes
			// 
			this.checkBoxMinutes.Checked = true;
			this.checkBoxMinutes.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkBoxMinutes.Location = new System.Drawing.Point(11, 129);
			this.checkBoxMinutes.Name = "checkBoxMinutes";
			this.checkBoxMinutes.Size = new System.Drawing.Size(188, 17);
			this.checkBoxMinutes.TabIndex = 39;
			this.checkBoxMinutes.Text = "Change background image every";
			this.checkBoxMinutes.CheckedChanged += new System.EventHandler(this.checkBoxMinutes_CheckedChanged);
			// 
			// textBoxMinutes
			// 
			this.textBoxMinutes.Location = new System.Drawing.Point(193, 126);
			this.textBoxMinutes.Name = "textBoxMinutes";
			this.textBoxMinutes.Size = new System.Drawing.Size(30, 20);
			this.textBoxMinutes.TabIndex = 40;
			// 
			// labelMinutes
			// 
			this.labelMinutes.AutoSize = true;
			this.labelMinutes.Location = new System.Drawing.Point(226, 130);
			this.labelMinutes.Name = "labelMinutes";
			this.labelMinutes.Size = new System.Drawing.Size(43, 13);
			this.labelMinutes.TabIndex = 41;
			this.labelMinutes.Text = "minutes";
			// 
			// panelPreview
			// 
			this.panelPreview.BackColor = System.Drawing.Color.Transparent;
			this.panelPreview.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelPreview.Location = new System.Drawing.Point(11, 172);
			this.panelPreview.Name = "panelPreview";
			this.panelPreview.Size = new System.Drawing.Size(552, 286);
			this.panelPreview.TabIndex = 42;
			this.panelPreview.Paint += new System.Windows.Forms.PaintEventHandler(this.panelPreview_Paint);
			// 
			// BackgroundChangerOptionsPage
			// 
			this.Controls.Add(this.panelPreview);
			this.Controls.Add(this.labelMinutes);
			this.Controls.Add(this.textBoxMinutes);
			this.Controls.Add(this.checkBoxMinutes);
			this.Controls.Add(this.checkBoxDifferentBackgrounds);
			this.Controls.Add(this.buttonNext);
			this.Controls.Add(this.trackBarTransparency);
			this.Controls.Add(this.labelTransparency);
			this.Controls.Add(this.buttonSelectDirectory);
			this.Controls.Add(this.labelPreview);
			this.Controls.Add(this.labelDirectory);
			this.Controls.Add(this.textBoxDirectory);
			this.Controls.Add(this.pictureBoxIcon);
			this.Controls.Add(this.linkLabelUpdate);
			this.Controls.Add(this.labelVersionInfo);
			this.Controls.Add(this.checkBoxEnabled);
			this.Controls.Add(this.labelAbout3);
			this.Controls.Add(this.linkLabelAbout2);
			this.Controls.Add(this.labelAbout1);
			this.Name = "BackgroundChangerOptionsPage";
			this.Size = new System.Drawing.Size(576, 487);
			this.Load += new System.EventHandler(this.BackgroundChangerOptionsPage_Load);
			this.PreparePage += new DevExpress.CodeRush.Core.OptionsPage.PreparePageEventHandler(this.CommenterOptionsPage_PreparePage);
			this.RestoreDefaults += new DevExpress.CodeRush.Core.OptionsPage.RestoreDefaultsEventHandler(this.CommenterOptionsPage_RestoreDefaults);
			this.CommitChanges += new DevExpress.CodeRush.Core.OptionsPage.CommitChangesEventHandler(this.CommenterOptionsPage_CommitChanges);
			((System.ComponentModel.ISupportInitialize)(this.pictureBoxIcon)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBarTransparency)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this)).EndInit();
			this.ResumeLayout(false);
			this.PerformLayout();

		} // InitializeComponent()
		#endregion

		#region Dispose
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
					components.Dispose();
			} // if (disposing)

			base.Dispose(disposing);
		} // Dispose(disposing)
		#endregion

		#region ShowPreview
		private void ShowPreview()
		{
			// Make sure we use the correct directory that is used in the
			// GetBackgroundImage method!
			Options.backgroundImageDirectory = textBoxDirectory.Text;

			// Get background image same way we would in ActiveViewBackgroundHelper
			Image backgroundImage = ActiveViewBackgroundHelper.GetBackgroundImage(0,
				ActiveViewBackgroundHelper.backgroundColorPixel,
				trackBarTransparency.Value / 100.0f);

			// Create graphics helper to paint onto the panelPreview
			Graphics previewGraphics = panelPreview.CreateGraphics();
			// Note: If no code window is open yet, this might be the wrong
			// background color and default to white, which is most peoples
			// code editor background color anyway.
			Color bgColor = ActiveViewBackgroundHelper.backgroundColorPixel;

			// Prepare dummy text we gonna display on top
			string dummyPreviewString =
		@"#region Load
/// <summary>
/// Load and set all options, happens at initialization and
/// whenever options are changed.
/// </summary>
public static void Load()
{
	Options.Load();

	// Make sure we kill all viewHelpers we got so far
	foreach (ActiveViewBackgroundHelper viewHelper in viewHelpers.Values)
		viewHelper.Dispose();
	viewHelpers.Clear();

	// And try to add the current view again to update it!
	AddCurrentViewToViewHelpers();
} // Load()
#endregion";

			// Display just bgColor if disabled
			if (backgroundImage == null)
			{
				previewGraphics.Clear(bgColor);
				// Make sure we tell the user that there are no images specified
				// yet or the thingy is deactivated
				dummyPreviewString = "No images found in the specified directory or " +
					"plugin is deactived!";
			}
			else
			{
				// Or just show the backgroundImage as specified
				previewGraphics.DrawImage(backgroundImage, 0, 0);
			}

			// Also display some text in inverted background color
			Font font = new Font(FontFamily.GenericMonospace, 9);
			SolidBrush textBrush = new SolidBrush(
				Color.FromArgb(255-bgColor.R, 255-bgColor.G, 255-bgColor.B));
			previewGraphics.DrawString(dummyPreviewString, font, textBrush, 1, 1);
			previewGraphics.Dispose();
		} // ShowPreview()
		#endregion // ShowPreview()

		#region Events
		/// <summary>
		/// Make sure the preview is updated when we load this form!
		/// </summary>
		private void BackgroundChangerOptionsPage_Load(object sender, EventArgs e)
		{
			ActiveViewBackgroundHelper.ClearBackgroundImage(false, false);
			ShowPreview();
		} // BackgroundChangerOptionsPage_Load(sender, e)

		/// <summary>
		/// And make sure we repaint every time the preview panel needs repainting.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void panelPreview_Paint(object sender, PaintEventArgs e)
		{
			ShowPreview();
		} // panelPreview_Paint(sender, e)

		/// <summary>
		/// Link label 1_ link clicked
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="e">E</param>
		private void linkLabel1_LinkClicked(object sender,
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			Process.Start("http://BenjaminNitschke.com");
		} // linkLabel1_LinkClicked(sender, e)

		private void checkBoxEnabled_CheckedChanged(object sender, EventArgs ea)
		{
			textBoxDirectory.Enabled = checkBoxEnabled.Checked;
			buttonSelectDirectory.Enabled = checkBoxEnabled.Checked;
			trackBarTransparency.Enabled = checkBoxEnabled.Checked;
			buttonNext.Enabled = checkBoxEnabled.Checked;
			checkBoxDifferentBackgrounds.Enabled = checkBoxEnabled.Checked;
			checkBoxMinutes.Enabled = checkBoxEnabled.Checked;
			textBoxMinutes.Enabled = checkBoxEnabled.Checked;

			ShowPreview();
		} // checkBoxEnabled_CheckedChanged(sender, ea)

		/// <summary>
		/// Commenter options page prepare page
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="ea">Event arguments</param>
		private void CommenterOptionsPage_PreparePage(object sender,
			DevExpress.CodeRush.Core.OptionsPageStorageEventArgs ea)
		{
			// Load options
			checkBoxEnabled.Checked = ea.Storage.ReadBoolean(
				"RandomBackgroundChangerOptions", "Enabled", true);
			textBoxDirectory.Text = ea.Storage.ReadString(
				"RandomBackgroundChangerOptions", "Directory", "");
			trackBarTransparency.Value = ea.Storage.ReadInt32(
				"RandomBackgroundChangerOptions", "Transparency", 25);
			labelTransparency.Text = "Transparency to make text easier to read: " +
				trackBarTransparency.Value + "% opacity";
			checkBoxMinutes.Checked = ea.Storage.ReadBoolean(
				"RandomBackgroundChangerOptions", "ChangeImageEveryFewMinutes", true);
			textBoxMinutes.Text = ea.Storage.ReadInt32(
				"RandomBackgroundChangerOptions", "MinutesToChangeImage", 5).ToString();
			checkBoxDifferentBackgrounds.Checked = ea.Storage.ReadBoolean(
				"RandomBackgroundChangerOptions", "DifferentImages", true);

			ShowPreview();
		} // CommenterOptionsPage_PreparePage(sender, ea)

		/// <summary>
		/// Commenter options page restore defaults
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="ea">Event arguments</param>
		private void CommenterOptionsPage_RestoreDefaults(object sender,
			DevExpress.CodeRush.Core.OptionsPageEventArgs ea)
		{
			// Restore default settings
			checkBoxEnabled.Checked = true;
			textBoxDirectory.Text = "";
			trackBarTransparency.Value = 25;
			
			ShowPreview();
		} // CommenterOptionsPage_RestoreDefaults(sender, ea)

		/// <summary>
		/// Commenter options page commit changes
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="ea">Event arguments</param>
		private void CommenterOptionsPage_CommitChanges(object sender,
			DevExpress.CodeRush.Core.OptionsPageStorageEventArgs ea)
		{
			// Save options
			ea.Storage.WriteBoolean(
				"RandomBackgroundChangerOptions", "Enabled", checkBoxEnabled.Checked);
			ea.Storage.WriteString(
				"RandomBackgroundChangerOptions", "Directory", textBoxDirectory.Text);
			ea.Storage.WriteInt32(
				"RandomBackgroundChangerOptions", "Transparency",
				trackBarTransparency.Value);
			ea.Storage.WriteBoolean(
				"RandomBackgroundChangerOptions", "ChangeImageEveryFewMinutes",
				checkBoxMinutes.Checked);
			try
			{
				ea.Storage.WriteInt32(
					"RandomBackgroundChangerOptions", "MinutesToChangeImage",
					Convert.ToInt32(textBoxMinutes.Text));
			}
			catch { } // ignore
			ea.Storage.WriteBoolean(
				"RandomBackgroundChangerOptions", "DifferentImages",
				checkBoxDifferentBackgrounds.Checked);

			ea.Storage.WriteStorageData();

			// Finally make sure we also update the VS windows (if transparency
			// changed for example)
			ActiveViewBackgroundHelper.ClearBackgroundImage(false, false);
		} // CommenterOptionsPage_CommitChanges(sender, ea)

		/// <summary>
		/// Link label update link clicked
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="e">E</param>
		private void linkLabelUpdate_LinkClicked(object sender,
			LinkLabelLinkClickedEventArgs e)
		{
			Process.Start("http://BenjaminNitschke.com");
		} // linkLabelUpdate_LinkClicked(sender, e)

		private void buttonSelectDirectory_Click(object sender, EventArgs e)
		{
			FolderBrowserDialog directoryDialog = new FolderBrowserDialog();
			directoryDialog.Description = "Select directory for background images";
			directoryDialog.ShowNewFolderButton = false;
			directoryDialog.SelectedPath = textBoxDirectory.Text;
			if (directoryDialog.ShowDialog() == DialogResult.OK)
			{
				textBoxDirectory.Text = directoryDialog.SelectedPath;

				ActiveViewBackgroundHelper.ClearBackgroundImage(true, true);
				ShowPreview();
			} // if
		} // buttonSelectDirectory_Click(sender, e)

		private void buttonNext_Click(object sender, EventArgs e)
		{
			ActiveViewBackgroundHelper.ClearBackgroundImage(false, true);
			ShowPreview();
		} // buttonNext_Click(sender, e)

		private void trackBarTransparency_Scroll(object sender, EventArgs e)
		{
			labelTransparency.Text = "Transparency to make text easier to read: " +
				trackBarTransparency.Value + "% opacity";

			ActiveViewBackgroundHelper.ClearBackgroundImage(false, false);
			ShowPreview();
		} // trackBarTransparency_Scroll(sender, e)

		private void checkBoxMinutes_CheckedChanged(object sender, EventArgs e)
		{
			textBoxMinutes.Enabled = checkBoxMinutes.Checked;
		} // checkBoxMinutes_CheckedChanged(sender, e)
		#endregion
	} // class BackgroundChangerOptionsPage
} // namespace CR_RandomBackgroundChanger
